package com.kbt.adapter;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import com.kbt.activity.GoodInfoActivity;
import com.kbt.activity.R;
import com.kbt.commont.Constants;
import com.kbt.fragment.GoodCarCompleteFragment;
import com.kbt.listener.ClickChangeGoodCountListener;
import com.kbt.listener.ClickCheckGoodListener;
import com.kbt.listener.ClickStartActivityListener;
import com.kbt.model.data.GoodForCarInfo;
import com.kbt.model.data.ShopCarBean;
import com.kbt.model.data.ShopCarListBean;
import com.kbt.model.data.ShopFenLeiBean;
import com.kbt.model.holder.GoodForCompCarInfoHolder;
import com.kbt.model.holder.GoodForEditCarInfoHolder;
import com.kbt.util.data.StaticData;
import com.kbt.util.utils.ImageManager;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhgk
 * @package: com.kbt.adapter
 * @TODO: <请描述这个类是干什么的>
 * @data: 2015/8/12 14:42
 * @version: V1.0
 */
public class GoodCarCompleteAdapter extends BaseAdapter {
    //商品数据列表
    private List<ShopCarBean> goodInfoList;
    //生命上下文
    private Activity context;
    //总价格
    private TextView totalView;
    private ImageLoader imageLoader;

    public GoodCarCompleteAdapter(Activity context, List<ShopCarBean> goodInfoList, TextView totalView) {
        this.goodInfoList = goodInfoList;
        this.context = context;
        this.totalView = totalView;
        this.imageLoader = ImageLoader.getInstance();
    }

    @Override
    public int getCount() {
        return goodInfoList.size();
    }

    @Override
    public Object getItem(int position) {
        return goodInfoList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    /**
     * 再次赋值
     *
     * @param mlist
     */
    public void setList(List<ShopCarBean> mlist) {
        goodInfoList = mlist;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        GoodForCompCarInfoHolder itemHolder;

        if (convertView == null) {
            itemHolder = new GoodForCompCarInfoHolder();

            LayoutInflater layoutInflater = LayoutInflater.from(context);
            convertView = layoutInflater.inflate(R.layout.good_car_complete_item, null);

            itemHolder.setGoodCheckBox((CheckBox) convertView.findViewById(R.id.car_good_check));
            itemHolder.setGoodImg((ImageView) convertView.findViewById(R.id.car_good_img));
            //itemHolder.setGoodTitle((TextView) convertView.findViewById(R.id.car_good_title));
            itemHolder.setGoodPrice((TextView) convertView.findViewById(R.id.car_good_price));
            itemHolder.setGoodTitle((TextView) convertView.findViewById(R.id.car_good_title));
            itemHolder.setGoodCount((TextView) convertView.findViewById(R.id.car_good_count));
            itemHolder.setKucun((TextView) convertView.findViewById(R.id.kucun));
            convertView.setTag(itemHolder);
        } else {
            itemHolder = (GoodForCompCarInfoHolder) convertView.getTag();
        }

        final ShopCarBean goodInfo = goodInfoList.get(position);
        itemHolder.getKucun().setText("库存:"+goodInfo.getStore_counts());
        if(goodInfo.getGoods_status().equals("1")) {
            itemHolder.getGoodCheckBox().setChecked(true);
        }else{
            itemHolder.getGoodCheckBox().setChecked(false);
        }
        imageLoader.displayImage(Constants.ServiceInterFace.imageURL + goodInfo.getGoods_icon(), itemHolder.getGoodImg(), ImageManager.getOptions(
                R.drawable.loadings, R.drawable.loadings));
        itemHolder.getGoodTitle().setText(goodInfo.getGoods_title());
        itemHolder.getGoodPrice().setText(goodInfo.getGoods_new_price()+"");
        itemHolder.getGoodCount().setText("" + goodInfo.getGoods_count());

        itemHolder.getGoodImg().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, GoodInfoActivity.class);
                intent.putExtra("shopId",goodInfo.getGoods_id()+"");
                context.startActivity(intent);
            }
        });

        return convertView;
    }


}
